package com.liwang.lanouhn.nvshengo.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.liwang.lanouhn.nvshengo.R;
import com.liwang.lanouhn.nvshengo.adapter.ViewPagerLivesAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 2016/9/29.
 */
public class LivesFragment extends Fragment {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<String> tabNames;
    private List<Fragment> fragments;
    private ViewPagerLivesAdapter viewPagerLivesAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_lives, null);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView(getView());
        initData();
    }


    private void initView(View view) {
        tabLayout = (TabLayout) view.findViewById(R.id.tab_lives);
        viewPager = (ViewPager) view.findViewById(R.id.vp_lives);
    }

    private void initData() {
        tabNames = new ArrayList<>();
        tabNames.add("游戏女神");
        tabNames.add("衣品达人");
        fragments = new ArrayList<>();
        CosmeticLiveFragment cosmeticlive = new CosmeticLiveFragment();
        fragments.add(cosmeticlive);
        DressLiveFragment dresslive = new DressLiveFragment();
        fragments.add(dresslive);
        viewPagerLivesAdapter = new ViewPagerLivesAdapter(getFragmentManager(), tabNames, fragments);
        viewPager.setAdapter(viewPagerLivesAdapter);
        tabLayout.setupWithViewPager(viewPager );


    }


}
